package com.timoon.webcomponent.utility.helpinfo;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.request.resource.PackageResourceReference;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.timoon.app.resource.image.ImageLocation;
import com.timoon.page.Page1;
import com.timoon.sample.dao.model.InfoSort;
import com.timoon.sample.utils.SystemConfig;
import com.timoon.webcomponent.utility.helpinfo.cell.HelpInfoCellPanel;

/**
 *<p>功能:</p>
 *<p></p>
 *<p>Copyright:Copyright(c)2013</p>
 *<p>Company:sky</p>
 *@author 付乐天
 *@version 1.0 */

public class HelpInfoPanel extends Panel {
	
	@SpringBean(name="sample.InfoMedium")
	private HelpInfoService service;
	
	@SpringBean(name="sample.infoSort")
	private InfoSortService infoSortService;
	
	private Class<? extends WebPage> targetPage;

	public HelpInfoPanel(String id,Class<? extends WebPage> targetPage) {
		super(id);
		// TODO Auto-generated constructor stub
		
		this.targetPage=targetPage;
		
		
		renderPanel();
	}

	private void renderPanel() {
		// TODO Auto-generated method stub
		
		
		renderGuide();
		
		renderPaid();
		
		renderSend();
		
		renderService();
		
		renderContact();
	}

	private void renderContact() {
		// TODO Auto-generated method stub
		add(new Image("wk_phone", new PackageResourceReference(ImageLocation.class,"other/phonecall.png")));
		
		add(new Image("wk_qq", new PackageResourceReference(ImageLocation.class,"other/qq.png")));
		
		InfoSort infoSort1=this.infoSortService.getUniqueInfoSortByType(SystemConfig.INFO_SORT_TYPE_PHONE);
		InfoSort infoSort2=this.infoSortService.getUniqueInfoSortByType(SystemConfig.INFO_SORT_TYPE_QQ);
		
		if(infoSort1==null){
			throw new RuntimeException("当从表【InfoSort】中尝试获取【TYPE="+SystemConfig.INFO_SORT_TYPE_PHONE+"】作为【号码】时，结果为null");
		}
		if(infoSort2==null){
			throw new RuntimeException("当从表【InfoSort】中尝试获取【TYPE="+SystemConfig.INFO_SORT_TYPE_QQ+"】作为【QQ】时，结果为null");
		}
		
		add(new Label("wk_phonelabel",infoSort1.getValue()));
		
		add(new Label("wk_qqlabel",infoSort2.getValue()));
	}

	private void renderService() {
		// TODO Auto-generated method stub
		add(new HelpInfoCellPanel("wk_service",SystemConfig.HELP_INFO_PANEL_SERVICE_TITLE,SystemConfig.HELP_INFO_PANEL_SERVICE_TYPE,targetPage,this.service));
	}

	private void renderSend() {
		// TODO Auto-generated method stub
		add(new HelpInfoCellPanel("wk_send",SystemConfig.HELP_INFO_PANEL_SEND_TITLE,SystemConfig.HELP_INFO_PANEL_SEND_TYPE,targetPage,this.service));
	}

	private void renderPaid() {
		// TODO Auto-generated method stub
		
		add(new HelpInfoCellPanel("wk_paid",SystemConfig.HELP_INFO_PANEL_PAID_TITLE,SystemConfig.HELP_INFO_PANEL_PAID_TYPE,targetPage,this.service));
		
	}

	private void renderGuide() {
		// TODO Auto-generated method stub
		add(new HelpInfoCellPanel("wk_guide",SystemConfig.HELP_INFO_PANEL_CELL1_TITLE,SystemConfig.HELP_INFO_PANEL_CELL1_TYPE,targetPage,this.service));
	}

}
